$(function(){
	var url='../exam/questionbankFillingInfo?qbId='+$("#qbid").val();
	var qbid=$("#qbid").val();
	$('#questionbankFilling').datagrid({
	    url:url,
	    columns:[[
	    	{field:'gapFillingId',title:"编号",width:50,align:'center'},
			{field:'examQuestion',title:"考题",width:300,align:'center'},
			{field:'answer',title:"答案",width:150,align:'center'},
			{field:'createPeople',title:"创建人",width:80,align:'center'},
			{field:'createDate',title:"创建时间",width:150,align:'center'},
			{field:'',width:100,align:'center',checkbox:true}
	    ]],
		fit:true,
		method:'get',
		toolbar:'#questionbankfill_tb',
		rownumbers:true,
		width: 700,
		height: 250,
		//显示分页栏
		pagination:true,
		//设置每页大小
		pageSize:5,
		//可选的每页大小
		pageList:[5,10,20,50],
	});
	$("#questionbankFillingDelete").bind('click',function(){
		var rows = $('#questionbankFilling').datagrid('getSelections');
		var fillingIds=[];
		for(var i=0;i<rows.length;i++){
			fillingIds.push(rows[i].gapFillingId);
		}
		var wjl_rowdata=JSON.stringify(fillingIds);
		alert(wjl_rowdata);
		$.ajax({
			url:"../exam/deleteQuestionBankFilling",
			data:{"wjl_rowdata":wjl_rowdata},
			success : function(e) {
				if (e.success) {
					$('#questionbankFilling').datagrid('load');
                   alert("删除成功");
                   
				}
			}
			
		});
	});
	$("#addQuestionbankFilling").on('click',function(){
		$("#wjladdquestionbankFilling").window("open");
	});
	$('#wjladdquestionbankFilling').dialog({
		buttons : [ {
			text : '保存',
			iconCls : 'icon-save',
			handler : function() {
				$('#ff2').form('submit', {
					onSubmit : function(param) {
						var examQuestion=$("#examQuestion2").val();
						var answer=$("#answer2").val();
						var qbId=""+qbid;
						var fillings=[];
						var filling={
								examQuestion:examQuestion,
								answer:answer,
								qbId:qbId
						}
						fillings.push(filling);
						var jsondata = JSON.stringify(fillings);
						$.ajax({
							url:"../exam/addquestionbanFilling",
							data : {"jsondata" : jsondata},
							success : function(data) {
								if (data.success) {
	                               alert("存储成功");
	                               $("#questionbankFilling").datagrid("load");
								}else{
									alert("存储失败")
								}
							}
						});

						$("#wjladdquestionbankFilling").window("close");
					},
					success : function(data) {
						alert(data)
					}
				});

			}
		}, {
			text : '清空',
			iconCls : 'icon-clear',
			handler : function() {
				$('#ff2').form('clear');
			}
		}, {
			text : '取消',
			iconCls : 'icon-cancel',
			handler : function() {
				$("#wjladdquestionbankFilling").window("close");
			}
		} ]
	});
$("#addQuestionbankfilling_search").bind('click',function(){
		
		var select=$("#addQuestionbankFilling_select").val();
		if(select=="单选"){
			update_wjl("../exam/questionbankSingleChoice");
		}else if(select=="多选"){
			update_wjl("../exam/questionbankMultiSelect");
		}else if(select=="判断"){
			update_wjl("../exam/questionbankJudge");
		}else if(select=="综合"){
			update_wjl("../exam/questionbankComprehensive");
		}
		
		
	});
	/*$.ajax({
		url:url,
		datatype:'json',
		success:function(result){
			var result=JSON.stringify(result);
			
		}
	})*/
})